<?php 
/*****************
*页面调用价格或版本数据
*创建日期:2012-5-8
*作者：yuantuan
******************/
header("expires:mon,26 jul 1997 05:00:00 gmt");  
header("cache-control:no-cache,must-revalidate");  
header("pragma:no-cache");
define('IN_WONDERSHARE', true);

if( $_GET['code'] != md5('product') ) {
	exit('error code!');
}

require( '../../inc/config.inc.php');
require( '../../includes/cls_mysql.php');
require( '../../inc/Function.php');
if(empty($db))
{
	$db = new cls_mysql($db_host, $db_user, $db_pass, $db_name);
}

/**
* 函数名：getProductInformation($db)
* 描述：得到产品价格或版本
* @params $db 操作数据库对象
* @params $productId 产品id
* @params $info 产品获取内容信息
* @return  int
*/
function getProductInformation($db,$productId,$info)
 {
						
			$sql = "SELECT `won_product_id` FROM `won_product` 
					WHERE `won_product_delete` = 0 AND `id` = '{$productId}'";	
			$id = $db->getOne($sql);
	if ($info=='price')
	{
		//price 
			$sql = "SELECT count(*) AS total FROM `license` 
					WHERE `license_id` = 11 AND `website_display` = 1 AND `license_delete` = 0 AND `product_id` = '{$id}'";
			$total = $db->getOne($sql);

			if( $total )
			{			
				$sql = "SELECT `product_is_year_charge` FROM product WHERE `product_delete` = 0 AND `product_id` = '{$id}'";
				$product_year = $db->getOne($sql);
	
				$price_one = get_price_license( $id, 11);
				$product_price = explode('.', $price_one['curr']);
				
				$price = '$'.$product_price[0].'.'.$product_price[1];//目前价格
				$price_old = isset($price_one['unique']) ? '<del>'.'$'.$price_one['old'].'</del>' : '';//促销前价格
				if($product_year) $price = $product_year ? '/Year' : '';//是否一年的费用
				$str = $price_old.' '.$price;
			}		
		
     }
	 elseif($info=='version')
	 {
			$sql = "SELECT `version_name` FROM `version` 
					WHERE `is_sale` = 1 AND `product_id` = '{$id}'";
			$version_name = $db->getOne($sql);
			if( $version_name )
			{			
				$str = $version_name;
			}	
	 }
			
	return $str; 
}
/**
* 函数名：productReview($db)
* 描述：得到产品评论信息
* @params $db 操作数据库对象
* @params $productId 产品id
* @return  array
*/
function productReview($db,$webType)
{
	/*
	$sql="SELECT 
	`pid`,`review`,`username`,`star` 
	FROM  `product_reviews_detail` 
	WHERE `check_state`=1 AND `web_type`='{$webType}' ORDER BY `did` DESC LIMIT 1";
	$rows = $db->getOneRs($sql);
	*/
	
	$sql="SELECT 
	`pid`,`review`,`username`,`star` 
	FROM  `product_reviews_detail` 
	WHERE `check_state`=1 AND `web_type`='{$webType}' ORDER BY `did` DESC LIMIT 1";
	$rows = $db->getOneRs($sql);

	$rows = $db->getOneRs($sql);
	//取产品名称
	$sql = "SELECT p.`product_name` 
	FROM `won_product` as won 
	LEFT JOIN `product` as p 
	ON won.`won_product_id`=p.`product_id` 
	 WHERE won.id='{$rows['pid']}'";
	$product_name = $db->getOne($sql);
	$rows['product_name'] = $product_name;
	return $rows ? serialize($rows) : '';
}
/**
* 函数名：productReview($db)
* 描述：得到产品评论信息
* @params $db 操作数据库对象
* @params $productId 产品id
* @return  array
*/
function ReviewStarCount($db,$product_id)
{
	$sql="SELECT 
	count(`did`) as c,sum(`star`) as s 
	FROM  `product_reviews_detail` 
	WHERE `check_state`=1 AND `pid`='{$product_id}'";
	//1count,2star
	$rows = $db->getOneRs($sql);
	return $rows ? serialize($rows) : '';
}
switch ($_GET['fun'])
{
	case 'review':
		echo productReview($db,$_GET['web_type']);
	break;
	case 'starcount':
		echo ReviewStarCount($db,$_GET['id']);
	break;
	default:
		echo getProductInformation($db,$_GET['id'],$_GET['info']);
}


?>